package com.example.xiaoxueqixiangmu.jiemian;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;

import com.example.xiaoxueqixiangmu.R;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class OrderGaiActivity extends AppCompatActivity {
    private TextView tv_userName,tv_cheming2,tv_riqi,textView2;
    private Button btn_ChaMa;
    private List<HashMap<String, Object>> listItems;
    private SimpleAdapter simpleAdapter;
    private ListView listView3;
    private static  final int REQUEST_CODE=101;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_order_gai);
        btn_ChaMa=findViewById(R.id.btn_ChaMa);


        listItems = new ArrayList<HashMap<String, Object>>();
        Intent intent = getIntent();
        List<HashMap<String, Object>> OC_dataList = (List<HashMap<String, Object>>) intent.getSerializableExtra("list");
for (HashMap<String,Object> map:OC_dataList){

    final HashMap<String,Object> map1;
    map1 =new HashMap<>();
    map1.put("tv_userName",map.get("tv_userName"));
    map1.put("tv_cheming2", map.get("tv_cheming2"));
    map1.put("tv_riqi", map.get("tv_riqi"));
    map1.put("textView2",map.get("textView2"));
    listItems.add(map1);

}
       /* final HashMap<String, Object> map1,map2,map3;
        map1=new HashMap<>();
        map1.put("listView",OC_dataList);
        map1.put("tv_cheming2", OC_dataList.get(0));
        map1.put("tv_riqi", OC_dataList.get(0));
        map1.put("textView2", OC_dataList.get(0));
        listItems.add(map1);

        map2=new HashMap<>();
        map2.put("tv_userName",OC_dataList.toString());
        map2.put("tv_cheming2", OC_dataList.toString());
        map2.put("tv_riqi", OC_dataList.toString());
        map2.put("textView2", OC_dataList.toString());
        listItems.add(map2);

        map3=new HashMap<>();
        map3.put("tv_userName",OC_dataList.toString());
        map3.put("tv_cheming2", OC_dataList.toString());
        map3.put("tv_riqi", OC_dataList.toString());
        map3.put("textView2", OC_dataList.toString());
        listItems.add(map3);
*/


       simpleAdapter = new SimpleAdapter(this, listItems, R.layout.order_control_item_layout,
                new String[]{"tv_userName", "tv_cheming2", "tv_riqi","textView2"}, new
                int[]{R.id.tv_userName, R.id.tv_cheming2, R.id.tv_riqi,  R.id.textView2});
       listView3 = findViewById(R.id.gai_listView);
        listView3.setAdapter(simpleAdapter);

        listView3.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
                if (position>=0){
                       new AlertDialog.Builder(OrderGaiActivity.this)
                               .setTitle("请选择操作")
                               .setIcon(R.drawable.tishi)
                               .setItems(R.array.tuipiao, new DialogInterface.OnClickListener() {
                                   @Override
                                   public void onClick(DialogInterface dialog, int which) {
                                       if (which==0){
                                             listItems.remove(position);
                                             simpleAdapter.notifyDataSetChanged();
                                           Toast.makeText(OrderGaiActivity.this, "退票成功", Toast.LENGTH_SHORT).show();
                                       }else if(which==2)
                                       {
                                           Toast.makeText(OrderGaiActivity.this,"取消修改",Toast.LENGTH_SHORT).show();
                                       }


                                   }
                               })
                               .create()
                               .show();

                    Toast.makeText(OrderGaiActivity.this, "你点击了第"+(position+1)+"项", Toast.LENGTH_SHORT).show();

                }

            }
        });

        //查看列表生成二维码的按钮监听事件
        btn_ChaMa.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(OrderGaiActivity.this,ErWeiMaActivity.class);
                startActivity(intent);

            }
        });
    }
}